<?php

namespace app\admin\controller;

use app\admin\model\DepartmentModel;
use app\BaseController;

class Test extends BaseController
{
    public function index()
    {
        $p = ['where' => [], 'page' => 'all','field'=>'id,parentid'];
        $list = DepartmentModel::getList($p)->toArray();
        $list = array_column($list, null, 'id');
        foreach ($list as $k=>$item){
            if($item['parentid'])
                $list[$item['parentid']]['children'][]=$item['id'];
        }
        api_return(200,'',$list);
//        $parent = 0;
//        $newsList=$this->recursion($list, $parent);
//        api_return(200, '',['list' => $newsList]);
    }
//
//    function recursion($list, $parent,$ids)
//    {
//        $data = [];
//        foreach ($list as $k => $item) {
//            if ($parent == $item['parentid']) {
//                unset($list[$k]);
//                $item['children'] = $this->recursion($list, $item['id']);
//                $data[] = $item;
//            }
//        }
//        return $data;
//    }

}
